package com.citytransport.prokopjuk.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.citytransport.prokopjuk.dao.DAOStation;
import com.citytransport.prokopjuk.route.Station;

public class StationListServlet extends AbstractCommand{
    private DAOStation daoStation = new DAOStation();
    private static final long serialVersionUID = -1766037387311139820L;
    static Logger logger = Logger.getLogger(RouteListServlet.class.getName());

    @Override
    public void processRequest(HttpServletRequest req, HttpServletResponse resp) {
	ArrayList<Station> stations = new ArrayList<Station>(daoStation.readAllStations());
	req.getSession(true).setAttribute("stations", stations);
	try {
	    req.getRequestDispatcher("/admin/stationList.jsp").forward(req, resp);
	} catch (ServletException e) {
	    logger.error(e);
	} catch (IOException e) {
	    logger.error(e);
	}
    }

}
